package com.pantech.app.call_log_enabler;

import android.app.Service;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.RemoteViews;

public class MyNumberService extends Service{
	private static final String LOGTAG = "callwidget";
	
	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void onCreate(){
		super.onCreate();
	}
	
	public int onStartCommand (Intent intent, int flags, int startId) {
		getMyPhoneNumber();
        RemoteViews views = 
        		new RemoteViews(getPackageName(), R.layout.calllogwidget_layout);
        views.setTextViewText(R.id.TVs, "MyNumber : " + getMyPhoneNumber());
        ComponentName thisWidget = new ComponentName(getApplicationContext(), CallLogEnablerWidget.class);
        AppWidgetManager manager = AppWidgetManager.getInstance(getApplicationContext());
        manager.updateAppWidget(thisWidget, views);
		return super.onStartCommand(intent, flags, startId);
	}
	
	private CharSequence getMyPhoneNumber() {
		// TODO Auto-generated method stub
		TelephonyManager mTelephonyMgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
		String myphoneNumber = mTelephonyMgr.getLine1Number();
		RemoteViews views = 
        		new RemoteViews(getPackageName(), R.layout.calllogwidget_layout);
        views.setTextViewText(R.id.TVs, myphoneNumber);
		return myphoneNumber;
	}//end getMyPhoneNumber()
	
	
}//end class
